﻿@using PayrollExpress.Helpers;
@using PayrollExpress.Models;
@model UserAddEditModel

@Html.Partial("_BreadCrumb", Model.BreadCrumb)

@using (Html.BeginForm(BaseHelper.PageAddEditSave.UserSave.ToString(), Model.ControllerName, FormMethod.Post, new { id = "saveForm" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    
    <fieldset>
    
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-8">
                    <div class="ibox float-e-margins">

                        <div class="ibox-title">
                            <div>@Html.ValidationMessageFor(m => m.Type.UserName)</div>
                            <div>@Html.ValidationMessageFor(m => m.Password)</div>
                            <div>@Html.ValidationMessageFor(m => m.Type.RoleID)</div>
                            <div>@Html.ValidationMessageFor(m => m.Type.WorkLocationID)</div>
                        </div>

                        <div class="ibox-content">
                            <table class="table table-bordered table-striped table-hover">
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.UserName)</th>
                                    <td>
                                        @Html.HiddenFor(m => m.Type.ID)
                                        @if (Model.PageAction == BaseHelper.PageAction.Add.ToString())
                                        {
                                            @Html.TextBoxFor(m => m.Type.UserName, new { @class = "single-line" }) 
                                        }
                                        else
                                        {
                                            @Html.DisplayFor(m => m.Type.UserName)
                                            @Html.HiddenFor(m => m.Type.UserName)
                                        }
                                    </td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Password)</th>
                                    <td>
                                        @if (Model.PageAction == BaseHelper.PageAction.Add.ToString())
                                        { 
                                            @Html.PasswordFor(m => m.Password, new { @class = "single-line" })
                                        }
                                        else
                                        {
                                            @Html.DisplayFor(m => m.Password)
                                            @Html.HiddenFor(m => m.Password)
                                        }
                                    </td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.RoleID)</th>
                                    <td>@Html.DropDownListFor(m => m.Type.RoleID, Model.Roles, new { @class = "single-line" })</td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.WorkLocationID)</th>
                                    <td>@Html.DropDownListFor(m => m.Type.WorkLocationID, Model.WorkLocations, new { @class = "single-line" })</td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.IsActive)</th>
                                    <td>@Html.CheckBoxFor(m => m.Type.IsActive)</td>
                                </tr>
                            </table>

                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th class="k-grid-header">
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasAdministrationAccess, new { @class = "chkAllAdmin", @onclick = "chkAll(this, '.chkAdmin')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasAdministrationAccess)
                                                </li>
                                            </ul>
                                        </th>
                                        <th class="k-grid-header">
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasMasterFilesAccess, new { @class = "chkAllMaster", @onclick = "chkAll(this, '.chkMaster')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasMasterFilesAccess)
                                                </li>
                                            </ul>
                                        </th>
                                        <th class="k-grid-header">
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasWorkspaceAccess, new { @class = "chkAllWorkspace", @onclick = "chkAll(this, '.chkWorkspace')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasWorkspaceAccess)
                                                </li>
                                            </ul>
                                        </th>
                                        <th class="k-grid-header">
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasReportsAccess, new { @class = "chkAllReports", @onclick = "chkAll(this, '.chkReports')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasReportsAccess)
                                                </li>
                                            </ul>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasUsersAccess, new { @class = "chkAdmin", @onclick = "checkMe('.chkAdmin', '.chkAllAdmin')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasUsersAccess)
                                                </li>
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasEmploymentTypesAccess, new { @class = "chkAdmin", @onclick = "checkMe('.chkAdmin', '.chkAllAdmin')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasEmploymentTypesAccess)
                                                </li>
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasRecurringHolidaysAccess, new { @class = "chkAdmin", @onclick = "checkMe('.chkAdmin', '.chkAllAdmin')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasRecurringHolidaysAccess)
                                                </li>
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasWorkLocationsAccess, new { @class = "chkAdmin", @onclick = "checkMe('.chkAdmin', '.chkAllAdmin')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasWorkLocationsAccess)
                                                </li>
                                            </ul>
                                        </td>
                                        <td>
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasHolidaysAccess, new { @class = "chkMaster", @onclick = "checkMe('.chkMaster', '.chkAllMaster')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasHolidaysAccess)
                                                </li>
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasEmployeesAccess, new { @class = "chkMaster", @onclick = "checkMe('.chkMaster', '.chkAllMaster')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasEmployeesAccess)
                                                </li>
                                            </ul>
                                        </td>
                                        <td>
                                            <ul class="checkbox">
                                                <li>
                                                    @Html.CheckBoxFor(m => m.UserAccess.HasPayrollAccess, new { @class = "chkWorkspace", @onclick = "checkMe('.chkWorkspace', '.chkAllWorkspace')" })
                                                    @Html.LabelFor(m => m.UserAccess.HasPayrollAccess)
                                                </li>
                                            </ul>
                                        </td>
                                        <td>
                                            <ul class="checkbox">
                                                
                                            </ul>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <p></p>
                            <button type="submit" id="btnSave" class="btn btn-primary" name="command" value=@Model.PageAction>@BaseHelper.PageAction.Save.ToDescription()</button>
                            <button type="submit" id="btnCancel" class="btn btn-primary cancel" name="command" value="@BaseHelper.PageAction.Cancel.ToString()">@BaseHelper.PageAction.Cancel.ToDescription()</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    
    </fieldset>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    <script type="text/javascript">

        $(document).ready(function () {
            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    return false;
                }
            });
        });

        function chkAll(me, chkClass) {
            var val = $(me).is(':checked');

            $(chkClass).each(function () {
                $(this).prop("checked", val);
            });
        }

        function checkMe(chkMe, chkAll) {
            var allIsChecked = true;

            $(chkMe).each(function () {
                val = $(this).is(':checked');

                if (!val)
                    allIsChecked = false;
            });

            $(chkAll).prop('checked', allIsChecked);
        }

        function CheckAccess() {
            var val = $('#ddlRole').val();

            if (val == 1) {
                $('.chkAllAdmin').prop('checked', true);
                $('.chkAdmin').prop('checked', true);

                $('.chkAllMaster').prop('checked', true);
                $('.chkMaster').prop('checked', true);

                $('.chkAllWorkspace').prop('checked', true);
                $('.chkWorkspace').prop('checked', true);

                $('.chkAllReports').prop('checked', true);
                $('.chkReports').prop('checked', true);
            }
            else {
                $('.chkAllAdmin').prop('checked', false);
                $('.chkAdmin').prop('checked', false);

                $('.chkAllMaster').prop('checked', false);
                $('.chkMaster').prop('checked', false);

                $('.chkAllWorkspace').prop('checked', false);
                $('.chkWorkspace').prop('checked', false);

                $('.chkAllReports').prop('checked', false);
                $('.chkReports').prop('checked', false);
            }
        }

    </script>



}